import { mapState } from 'vuex'

export const mixinFetchEmp = {
  data() {
    return {
      pageParams: {
        name: undefined,
        page: 1,
        pageSize: 10
      }
    }
  },
  methods: {
    async fetchEmployeeList() {
      try {
        await this.$store.dispatch('employeeStore/fetchEmployeeListAction', this.pageParams)
      } catch (error) {
        this.$message.error(error.message)
      }
    },
    handleSizeChange(pageSize) {
      this.pageParams.pageSize = pageSize
      this.fetchEmployeeList()
    },
    handleCurrentChange(page) {
      this.pageParams.page = page
      this.fetchEmployeeList()
    }
  },
  mounted() {
    this.fetchEmployeeList()
  },
  computed: {
    ...mapState('employeeStore', ['total', 'records'])
  }
}
